﻿namespace PowerSong.UserInterface.Tasks
    {
    using System;
    using PowerSong.Import;

    public class ImportTask : Task
        {

        private BaseImport importer = null;

        private string categoryName = null;

        public string[] Messages { get; private set; }

        public ImportTask(BaseImport importer, string categoryName, string taskDescription)
            : base("Importing Data", taskDescription)
            {
            this.importer = importer;
            this.importer.ReportProgress += importer_ReportProgress;
            this.categoryName = categoryName;
            }

        private void importer_ReportProgress(int percentage, string status)
            {
            base.SetProgress(percentage, status);
            }

        public override void Execute()
            {
            this.Messages = importer.ImportData(this.categoryName);
            }

        public override void HandleException(Exception ex)
            {
            Utilities.ShowErrorMessage("Cannot Import Data", "The data could not be imported:", ex.Message);
            }

        }

    }
